#include <myheader_c_plus.h>
#include <set>
#include <unordered_set>
using std::endl;
using std::cout;
using std::unordered_multiset;
using std::multiset;
using std::ostream;
class Point{
public:
    Point(int x, int y)
        :_x(x)
         ,_y(y)
    {

    }

    float getDistance()const{
        return hypot(_x, _y); 
    }

    int getX()const{
        return _x;
    }

    int getY()const{
        return _y;
    }




    friend ostream & operator<<(ostream & os, const Point & rhs);
private:
    int _x;
    int _y;
};
ostream & operator<<(ostream & os, const Point & rhs){
    os <<"(" << rhs._x << "," << rhs._y << ")" ;
    return os;

}
//hash的实现第一种,模板特例化
namespace std{
template <>
    class hash<Point> {
    public:
        size_t operator()(const Point &point) const
        {
            cout << "hash" << endl;
            return (point.getX() << 1)^ (point.getY() << 1);
        }
    };
};
//end of namespace std
//equalto 的实现第一种方式
namespace std{
template<>
struct equal_to<Point>{
    bool operator()(const Point &lhs, const Point &rhs)const 
    {
        cout << "equal to" << endl;
        return lhs.getDistance() == rhs.getDistance();
    }
};
};
//重载运算符<第一种方式
bool operator<(const Point & lhs, const Point & rhs){
    cout << "operator < " << endl;
    float l = lhs.getDistance();
    float r = rhs.getDistance();
    if(l != r) return l < r;
    if(lhs.getX() != rhs.getX()) return lhs.getX() < rhs.getX();
    return lhs.getY() < rhs.getY();

}
template<typename Container>
void display(Container & con){
    for(auto & ele : con){
        cout << ele << " ";
    }
    cout << endl;
}
void test3(){
    unordered_multiset<Point> points = {
        Point(1,3),
        Point(-1,3),
        Point(0,3),
        Point(2,3),
        Point(1,3),
        Point(3,1)
    };
    display(points);


}
int main(int argc, char *argv[])
{
    test3();
    return 0;
}

